﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Chat
{
    /// <summary>
    /// SignInWindow.xaml 的交互逻辑
    /// </summary>
    public partial class SignInWindow : Window
    {
        public SignInWindow()
        {
            InitializeComponent();
        }

        private async void WhenSignIn(object sender, RoutedEventArgs e)
        {
            string name = txtName.Text.Trim();
            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("错误：请填写名称!");
                return;
            }
            Client.CurrentUser.Name = name;
            this.IsEnabled = false;
            await Client.StartClient()
                .ContinueWith((task) =>
                {
                    Client.CurrentService = task.Result;
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        new ChatWindow().Show();
                    });
                })
                .ContinueWith((task) =>
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.Hide();
                    });
                })
               ;
        }

    }
}
